AC_PREREQ(2.54)
AC_INIT([libanculus-sharp], 0.3.0, [http://code.google.com/p/libanculus-sharp/])
AM_INIT_AUTOMAKE([foreign])

AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
if test "x$PKG_CONFIG" = "xno"; then
        AC_MSG_ERROR([You need to install pkg-config])
fi

AC_PROG_INSTALL

AC_PATH_PROG(GMCS, gmcs, no)
if test "x$GMCS" = "xno"; then
        AC_MSG_ERROR([gmcs Not found])
fi

AC_PATH_PROG(GACUTIL, gacutil, no)
if test "x$GACUTIL" = "xno" ; then
	AC_MSG_ERROR([No gacutil tool found])
fi

ASSEMBLY_VERSION=0.3.0.0
AC_SUBST(ASSEMBLY_VERSION)

GACUTIL_FLAGS='/package libanculus-sharp /root $(DESTDIR)$(prefix)/lib'

AC_SUBST(GACUTIL)
AC_SUBST(GACUTIL_FLAGS)

MONO_REQUIRED_VERSION=1.2.3
PKG_CHECK_MODULES(MONO,mono >= $MONO_REQUIRED_VERSION, has_mono=true, has_mono=false)

if test "x$has_mono" = "xfalse"; then
      AC_MSG_ERROR([Please install mono version $MONO_REQUIRED_VERSION or later to install Anculus.
Please see http://www.mono-project.org/ to download latest mono sources or packages])
fi

AC_SUBST(prefix)

AC_ARG_ENABLE(gtk, AC_HELP_STRING([--enable-extended], [enable Core extensions [default=yes]]), enable_extended=${enableval}, enable_extended=yes)
AC_ARG_ENABLE(gtk, AC_HELP_STRING([--enable-gtk], [enable Gtk extensions [default=yes]]), enable_gtk=${enableval}, enable_gtk=yes)
AC_ARG_ENABLE(winforms, AC_HELP_STRING([--enable-winforms], [enable Winforms extensions [default=yes]]), enable_winforms=${enableval}, enable_winforms=yes)

if test "x$enable_gtk" = "xyes"; then
	GTKSHARP_REQUIRED_VERSION=2.8.0

	PKG_CHECK_MODULES(GLIB_SHARP, glib-sharp-2.0 >= $GTKSHARP_REQUIRED_VERSION)
	AC_SUBST(GLIB_SHARP_LIBS)
	PKG_CHECK_MODULES(GTK_SHARP, gtk-sharp-2.0 >= $GTKSHARP_REQUIRED_VERSION)
	AC_SUBST(GTK_SHARP_LIBS)

	gtksharp_prefix="`$PKG_CONFIG --variable=prefix gtk-sharp-2.0`"
	AC_SUBST(gtksharp_prefix)
fi

AM_CONDITIONAL(ENABLE_EXTENDED, [test x$enable_extended = xyes])
AM_CONDITIONAL(ENABLE_GTK, [test x$enable_gtk = xyes])
AM_CONDITIONAL(ENABLE_WINFORMS, [test x$enable_winforms = xyes])

AC_PATH_PROG(MDASSEMBLER, mdassembler, no)
AC_PATH_PROG(MONODOCER, monodocer, no)

if test "x$MONODOCER" = "xno" -o "x$MDASSEMBLER" = "xno"; then
	enable_monodoc=no
	doc_sources_dir=
else
	enable_monodoc=yes
	doc_sources_dir="`pkg-config --variable=sourcesdir monodoc`"
fi
AC_SUBST(MDASSEMBLER)
AC_SUBST(MONODOCER)

AM_CONDITIONAL(ENABLE_MONODOC, test "x$enable_monodoc" = "xyes")

ANCULUS_BUILD_DIR=`pwd`/build
ANCULUS_CORE_LIB='Anculus.Core.dll'
ANCULUS_CORE_EXTENDED_LIB='Anculus.Core.Extended.dll'
ANCULUS_GUI_LIB='Anculus.Gui.dll'

AC_SUBST(ANCULUS_BUILD_DIR)
AC_SUBST(ANCULUS_CORE_LIB)
AC_SUBST(ANCULUS_CORE_EXTENDED_LIB)
AC_SUBST(ANCULUS_GUI_LIB)

AC_OUTPUT([
Makefile
src/Makefile
src/Anculus.Core/Makefile
src/Anculus.Core/anculus-core.pc
src/Anculus.Core/AssemblyInfo.cs
src/Anculus.Core.Extended/Makefile
src/Anculus.Core.Extended/anculus-core-extended.pc
src/Anculus.Core.Extended/AssemblyInfo.cs
src/Anculus.Gui/Makefile
src/Anculus.Gui/anculus-gui.pc
src/Anculus.Gui/AssemblyInfo.cs
src/Anculus.Benchmark/Makefile
src/Anculus.Benchmark/AssemblyInfo.cs
src/Anculus.UnitTests/Makefile
docs/Makefile
docs/sources/Makefile
])

echo ""
echo "Configuration summary"
echo ""
echo "* Installation prefix : $prefix"
echo ""
echo "* Gui support:"
echo "*    Gtk extensions      : $enable_gtk"
echo "*    Winforms extensions : $enable_winforms"
echo ""
echo "* Documentation: $enable_monodoc"
echo "*    Monodoc sources     : $doc_sources_dir"
echo ""
